//
//  XZSTSCell.m
//  生活小助手
//
//  Created by lixiangzhou on 14-8-8.
//  Copyright (c) 2014年 lxz. All rights reserved.
//

#import "XZSTSCell.h"

#import "XZSTSTrainInfo.h"

@interface XZSTSCell ()
/*　	列次名称 */
@property (weak, nonatomic) UILabel *trainOppLabel;
///*　	列车类型 */
//@property (weak, nonatomic) UILabel *typenameLabel;
/*　	出发站 */
@property (weak, nonatomic) UILabel *startStationLabel;
/*　	终点站 */
@property (weak, nonatomic) UILabel *endStationLabel;
/*　	发车时间 */
@property (weak, nonatomic) UILabel *leaveTimeLabel;
/*　	到达时间 */
@property (weak, nonatomic) UILabel *arrivedTimeLabel;
/*　	里程 */
@property (weak, nonatomic) UILabel *mileageLabel;
@end

@implementation XZSTSCell

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *identifier = @"stsCell";
    XZSTSCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[XZSTSCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;
}


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        /* ------------------列次名称------------------*/
        UILabel *trainOppLabel = [[UILabel alloc] init];
        trainOppLabel.font = kFont;
        trainOppLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:trainOppLabel];
        self.trainOppLabel = trainOppLabel;

        /* ------------------出发站------------------*/
        UILabel *startStationLabel = [[UILabel alloc] init];
        startStationLabel.font = kFont;
        startStationLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:startStationLabel];
        self.startStationLabel = startStationLabel;
        
        /* ------------------终点站------------------*/
        UILabel *endStationLabel = [[UILabel alloc] init];
        endStationLabel.font = kFont;
        endStationLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:endStationLabel];
        self.endStationLabel = endStationLabel;
        
        /* ------------------到达时间------------------*/
        UILabel *arrivedTimeLabel = [[UILabel alloc] init];
        arrivedTimeLabel.font = kFont;
        arrivedTimeLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:arrivedTimeLabel];
        self.arrivedTimeLabel = arrivedTimeLabel;
        
        /* ------------------发车时间------------------*/
        UILabel *leaveTimeLabel = [[UILabel alloc] init];
        leaveTimeLabel.font = kFont;
        leaveTimeLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:leaveTimeLabel];
        self.leaveTimeLabel = leaveTimeLabel;
        
        
        /* ------------------里程------------------*/
        UILabel *mileageLabel = [[UILabel alloc] init];
        mileageLabel.font = kFont;
        mileageLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:mileageLabel];
        self.mileageLabel = mileageLabel;
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 列次名称
    self.trainOppLabel.width = kTrainOppWidth;
    self.trainOppLabel.height = self.height;
    
    // 站点
    self.startStationLabel.x = CGRectGetMaxX(self.trainOppLabel.frame);
    self.startStationLabel.height = self.height * 0.5;
    self.startStationLabel.width = kStationWidth;
    
    self.endStationLabel.height = self.height * 0.5;
    self.endStationLabel.width = kStationWidth;
    self.endStationLabel.x = self.startStationLabel.x;
    self.endStationLabel.y = CGRectGetMaxY(self.startStationLabel.frame);
    
    // 时间
    self.arrivedTimeLabel.x = CGRectGetMaxX(self.startStationLabel.frame);
    self.arrivedTimeLabel.height = self.height * 0.5;
    self.arrivedTimeLabel.width = kTimeWidth;
    
    self.leaveTimeLabel.width = kTimeWidth;
    self.leaveTimeLabel.height = self.height * 0.5;
    self.leaveTimeLabel.x = self.arrivedTimeLabel.x;
    self.leaveTimeLabel.y = CGRectGetMaxY(self.arrivedTimeLabel.frame);
    
    // 里程
    self.mileageLabel.x = CGRectGetMaxX(self.arrivedTimeLabel.frame);
    self.mileageLabel.width = kMileageWidth;
    self.mileageLabel.height = self.height;
}

- (void)setTrainInfo:(XZSTSTrainInfo *)trainInfo
{
    _trainInfo = trainInfo;
    
    self.trainOppLabel.text = trainInfo.trainOpp;
    self.startStationLabel.text = trainInfo.start_staion;
    self.endStationLabel.text = trainInfo.end_station;
    self.leaveTimeLabel.text = trainInfo.leave_time;
    self.arrivedTimeLabel.text = trainInfo.arrived_time;
    self.mileageLabel.text = trainInfo.mileage;
}

@end
